/******************************************************************************
*  HISTORY OF CHANGES
*   <Date>          <Author>        <Version>       <DESCRIPTION>
*   2017-12-14      yangyan           V1.0.0           original
******************************************************************************/
#include "main.h"

#include <stdio.h> 

#include <svdpi.h>


extern "C"  void fib_oa(const svOpenArrayHandle data_oa)
{
    int i, *data;
    data = (int *) svGetArrayPtr(data_oa);
    data[0] = 1;
    data[1] = 1;
    for (i = 2; i < 20; i++) {
        data[i] = data[i-1] + data[i-2];
    }
}
 


//void pass_array(const svOpenArrayHandle dyn_arr ) { 
//	printf("Array Pointer is %x \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n", svGetArrayPtr(dyn_arr) ); 
//	printf(" Lower index %d \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n", svLow(dyn_arr,1)); 
//	printf(" Higher index %d \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n", svHigh(dyn_arr, 1) ); 
//	printf(" Left index %d \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n", svLeft(dyn_arr,1)); 
//	printf(" Right index %d \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n", svRight(dyn_arr, 1) ); 
//	printf(" Length of array %d \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n", svLength(dyn_arr,1) ); 
//	printf(" Incremental %d \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n",svIncrement(dyn_arr,1)); 
//	printf("Dimentions of Array %d \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n", svDimensions(dyn_arr )); 
//	printf("Size of Array in bytes %d \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n", svSizeOfArray(dyn_arr) ); 
//}


extern "C"  int  my_read_data(svBitVecVal filter_data[64],svBitVecVal filter_data_exp[4],const svBitVecVal * addr) 
{
    printf("pe read data  test begin!\n");

    unsigned  int   temp ;
    for  (int i = 0; i < 4; i++)
    {
      for (int j = 0; j < 16; j++)
      {
        temp =  j ; 
        filter_data[i*16+j] =  (int) temp ;
      }
      int exponent  = i;
      filter_data_exp[i] = exponent;
    }
    printf("pe read data test end!\n");
    return 0 ;
}




extern "C"  int test_all()  // main������������Ҫ��Ϊ�������ŵ�����Ԥ���ӿ�
{
    //svOpenArrayHandle p_in ;
    //svGetArrayPtr(p_in);
    //printf("run begin %0d!",svGetArrayPtr(p_in));

    INT32   status;
    char  DirectoryName[256] = {0};
    char  DirectoryName1[256] = {0};
    int   prach_test = 0;
    int   SRS_test = 1;
	int   UCI_bit_test = 0;
    int   pusch_brp_test = 0;
    int   pucch_test = 0;
	int   pusch_test = 0;

    // ���������ļ����Ŀ¼
    if (1)
    {
        //create output file
        sprintf(DirectoryName, "Result");
        // ������εķ������ļ���
        status = mkdir(DirectoryName,0744);
        sprintf(DirectoryName, "Result/PUSCHPUCCHSRSTestData");
        status = mkdir(DirectoryName,0744); // ���ڱ�֤ɾ��ʱ������
        // ɾ���ϴεķ������ļ���
        system("rm -rf  Result/PUSCHPUCCHSRSTestData");
        printf("history %s del success\n", "Result/PUSCHPUCCHSRSTestData");
        status = mkdir(DirectoryName,0744); // ���ڴ洢���η�����

		sprintf(DirectoryName, "Result/PUSCHTestData");
		status = mkdir(DirectoryName,0744); // ���ڱ�֤ɾ��ʱ������
		// ɾ���ϴεķ������ļ���
		system("rm -rf  Result/PUSCHTestData");
		printf("history %s del success\n", "Result/PUSCHTestData");
		status = mkdir(DirectoryName,0744); // ���ڴ洢���η�����

        sprintf(DirectoryName, "Result/LDPCTestData");
        status = mkdir(DirectoryName,0744); // ���ڱ�֤ɾ��ʱ������
        // ɾ���ϴεķ������ļ���
        system("rm -rf  Result/LDPCTestData");
        printf("history %s del success\n", "Result/LDPCTestData");
        status = mkdir(DirectoryName,0744); // ���ڴ洢���η�����

        sprintf(DirectoryName, "Result/SCTestData");
        status = mkdir(DirectoryName,0744); // ���ڱ�֤ɾ��ʱ������
        // ɾ���ϴεķ������ļ���
        system("rm -rf  Result/SCTestData");
        printf("history %s del success\n", "Result/SCTestData");
        status = mkdir(DirectoryName,0744); // ���ڴ洢���η�����

        sprintf(DirectoryName, "Result/PRACHTestData");
        status = mkdir(DirectoryName,0744); // ���ڱ�֤ɾ��ʱ������
        // ɾ���ϴεķ������ļ���
        system("rm -rf  Result/PRACHTestData");
        printf("history %s del success\n", "Result/PRACHTestData");
        status = mkdir(DirectoryName,0744); // ���ڴ洢���η�����

        sprintf(DirectoryName, "Result/SRSTestData");
        status = mkdir(DirectoryName,0744); // ���ڱ�֤ɾ��ʱ������
        // ɾ���ϴεķ������ļ���
        system("rm -rf  Result/SRSTestData");
        printf("history %s del success\n", "Result/SRSTestData");
        status = mkdir(DirectoryName,0744); // ���ڴ洢���η�����

        sprintf(DirectoryName, "Result/PUCCHTestData");
        status = mkdir(DirectoryName,0744); // ���ڱ�֤ɾ��ʱ������
        // ɾ���ϴεķ������ļ���
        system("rm -rf  Result/PUCCHTestData");
        printf("history %s del success\n", "Result/PUCCHTestData");
        status = mkdir(DirectoryName,0744); // ���ڴ洢���η�����

        sprintf(DirectoryName,"Result/UCI_bit_para");
        status = mkdir(DirectoryName,0744); // ���ڱ�֤ɾ��ʱ������
        system("rm -rf  Result/UCI_bit_para");
        printf("history %s del success\n","Result/UCI_bit_para");
        status = mkdir(DirectoryName,0744); // ���ڴ洢���η�����
    }

        //system("read");


    if (prach_test)
    {
        prach_test_main(); // ĿǰPRACH�Ĳ�������prach_test_main������
        //system("PAUSE");
        system("read");
    }

	if (pusch_test && SRS_test)
	{
		pusch_pucch_srs_test_main(0);
		printf("pusch & srs test over\n");
	}
	else if (pucch_test && SRS_test)
	{
		pusch_pucch_srs_test_main(1);
		printf("pucch & srs test over\n");
	}
	else
	{
		if (pusch_test)
		{
			pusch_test_main();
			printf("pusch test over\n");
		}
		if (pucch_test)
		{
			pucch_test_main();
			printf("pucch test over\n");
		}
		if (SRS_test)
		{
			printf("srs test start\n");			
			srs_gen_main();
			printf("test over\n");
		}
	}

    if (UCI_bit_test)
    {
        uci_bit_test_main();
        //system("PAUSE");
        system("read");
    }
    if (pusch_brp_test)
    {
		pus_brp_wx_main();
        //system("PAUSE");
        system("read");
    }

    //system("PAUSE");
    system("read");

    return;
}



int main(void)
{
    test_all();
    return 0;
}


